<?php

namespace app\admin\controller;


use app\admin\model\AdminAuthGroup;
use app\admin\service\AdminGroupService;
use app\common\attributes\Menu;
use think\annotation\Inject;


class GroupController extends AdminBaseController
{

    #[Inject]
    protected AdminGroupService $service;

    #[Inject]
    protected AdminAuthGroup $model;

    /**
     * 角色详情
     *
     * @param $data
     *
     */
    #[Menu('查看角色详情')]
    public function read($group_id)
    {
        $res = AdminGroupService::getAdminGroupItem($group_id);
        return $this->success($res);
    }

    /**
     * 角色列表
     *
     * @throws \think\Exception
     */
    #[Menu('查看角色列表')]
    public function index()
    {

        $data = $this->getParams();
        //当前是否为关联查询
        //设置过滤方法
        $extendQueryHelper = $this->buildparams();
        $list = $this->service->getList($extendQueryHelper, $data);
        foreach ($list as $row) {

        }
        return $this->success($list);
    }

    /**
     * 修改角色
     *
     * @param $request
     *
     */
    #[Menu('修改角色')]
    public function update()
    {
        $data = $this->getParams();
        $res = AdminGroupService::setAdminGroupItem($data);
        return $this->success($res);
    }

    /**
     * 添加角色
     */
    #[Menu('添加角色')]
    public function save()
    {
        $data = $this->getParams();
        $res = AdminGroupService::addAdminGroupItem($data);
        return $this->success($res);
    }

    /**
     * 删除角色
     *
     * @throws \think\Exception
     */
    #[Menu('删除角色')]
    public function del($group_id) : \think\response\Json
    {
        $result = AdminGroupService::delAdminGroupItem($group_id);
        return $this->success($result);
    }
}